import { computed } from 'vue';
const authFieldColumns = [
  {
    title: '启用',
    dataIndex: 'switch',
    width: 80,
    align: 'center',
    slots: { customRender: 'switch' },
  },
  {
    title: '字段名称',
    width: 200,
    dataIndex: 'code',
  },
  {
    title: '字段描述',
    dataIndex: 'title',
  },
  {
    title: '列表控制',
    dataIndex: 'list',
    width: 120,
    slots: { customRender: 'list' },
  },
  {
    title: '表单控制',
    dataIndex: 'form',
    width: 180,
    slots: { customRender: 'form' },
  },
];
const authButtonColumns = [
  {
    title: '启用',
    dataIndex: 'switch',
    width: 80,
    slots: { customRender: 'switch' },
  },
  {
    title: '名称',
    dataIndex: 'title',
  },
  {
    title: '编码',
    dataIndex: 'code',
  },
  {
    title: '权限控制',
    dataIndex: 'control',
    width: 180,
    slots: { customRender: 'control' },
  },
];
const authButtonFixedList = [
  { code: 'add', title: '新增', status: 0 },
  { code: 'update', title: '编辑', status: 0 },
  { code: 'delete', title: '删除', status: 0 },
  { code: 'batch_delete', title: '批量删除', status: 0 },
  { code: 'export', title: '导出', status: 0 },
  { code: 'import', title: '导入', status: 0 },
  { code: 'bpm', title: '提交流程', status: 0 },
  { code: 'super_query', title: '高级查询', status: 0 },
];
const USE_SQL_RULES = 'USE_SQL_RULES';
const authDataColumns = [
  {
    title: '启用',
    dataIndex: 'switch',
    width: 80,
    slots: { customRender: 'switch' },
  },
  {
    title: '规则名称',
    dataIndex: 'ruleName',
    width: 130,
  },
  {
    title: '规则描述',
    dataIndex: 'description',
    customRender({ record: { ruleOperator, ruleValue, ruleColumn } }) {
      if (ruleOperator == USE_SQL_RULES) {
        return `自定义SQL: ${ruleValue}`;
      } else {
        return `${ruleColumn} ${ruleOperator} ${ruleValue}`;
      }
    },
  },
];
function useAuthDataFormSchemas(props, methods) {
  const formSchemas = computed(() => [
    {
      label: '规则名称',
      field: 'ruleName',
      required: true,
      component: 'Input',
    },
    {
      label: '规则字段',
      field: 'ruleColumn',
      component: 'JSearchSelect',
      componentProps: {
        dictOptions: props.authFields,
        getPopupContainer: () => document.body,
      },
      dynamicRules({ model }) {
        return [{ required: model.ruleOperator != USE_SQL_RULES, message: '请输入规则字段' }];
      },
      show: ({ model }) => model.ruleOperator != USE_SQL_RULES,
    },
    {
      label: '条件规则',
      field: 'ruleOperator',
      required: true,
      component: 'JDictSelectTag',
      componentProps: {
        dictCode: 'rule_conditions',
        onChange: methods.onRuleOperatorChange,
      },
    },
    {
      label: '规则值',
      field: 'ruleValue',
      required: true,
      component: 'Input',
    },
    {
      label: '状态',
      field: 'status',
      required: true,
      component: 'RadioButtonGroup',
      componentProps: {
        options: [
          { label: '有效', value: 1 },
          { label: '无效', value: 0 },
        ],
      },
      defaultValue: 1,
    },
  ]);
  return { formSchemas };
}
export { USE_SQL_RULES, authFieldColumns, authButtonColumns, authButtonFixedList, authDataColumns, useAuthDataFormSchemas };
